<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.0.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.0.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.0.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.0.4">


  <link rel="mask-icon" href="/images/logo.svg?v=6.0.4" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '6.0.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  
  <meta name="keywords" content="商城," />


<meta name="description" content="订单数据表结构mysql表 参考：http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecmall-database-mysqldb.html  订单表： sales_flat_order   订单详情表：sales_flat_order_item 商品表：product_flat  商品库存表：product_flat_q">
<meta name="keywords" content="商城">
<meta property="og:type" content="article">
<meta property="og:title" content="fecshop开源商城学习笔记">
<meta property="og:url" content="http://blog.yunshu168.com/posts/f5f4aa82.html">
<meta property="og:site_name" content="树下千云">
<meta property="og:description" content="订单数据表结构mysql表 参考：http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecmall-database-mysqldb.html  订单表： sales_flat_order   订单详情表：sales_flat_order_item 商品表：product_flat  商品库存表：product_flat_q">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2020-03-09T14:39:53.507Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="fecshop开源商城学习笔记">
<meta name="twitter:description" content="订单数据表结构mysql表 参考：http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecmall-database-mysqldb.html  订单表： sales_flat_order   订单详情表：sales_flat_order_item 商品表：product_flat  商品库存表：product_flat_q">






  <link rel="canonical" href="http://blog.yunshu168.com/posts/f5f4aa82.html"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>
  <title>fecshop开源商城学习笔记 | 树下千云</title>
  






  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?f8a99180bb75f49a4b2206cab6e25c50";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <!-- <div class="headband"></div>
<a href="https://github.com/yunshu2009"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a> -->
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">树下千云</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>


  



 </div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://blog.yunshu168.com/posts/f5f4aa82.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="云舒">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="树下千云">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">fecshop开源商城学习笔记</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <!--<span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>-->
              
                <!--<span class="post-meta-item-text">发表于</span>-->
              
              <!--<time title="创建于" itemprop="dateCreated datePublished" datetime="2020-02-09T17:14:22+08:00">2020-02-09</time>-->
            

            
            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/技术/" itemprop="url" rel="index"><span itemprop="name">技术</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          


          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="订单"><a href="#订单" class="headerlink" title="订单"></a>订单</h3><h4 id="数据表结构"><a href="#数据表结构" class="headerlink" title="数据表结构"></a>数据表结构</h4><p><strong>mysql表</strong></p>
<p>参考：<a href="http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecmall-database-mysqldb.html" target="_blank" rel="noopener">http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecmall-database-mysqldb.html</a> </p>
<p>订单表： sales_flat_order   订单详情表：sales_flat_order_item 商品表：product_flat  商品库存表：product_flat_qty  属性表：product_attribute</p>
<p><strong>mongodb集合</strong></p>
<p>参考：<a href="http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecmall-database-mongodb.html" target="_blank" rel="noopener">http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecmall-database-mongodb.html</a></p>
<p>错误日志表：error_handler_log   产品收藏信息表 Favorite   订阅邮件：newsletter</p>
<a id="more"></a>
<h4 id="订单状态"><a href="#订单状态" class="headerlink" title="订单状态"></a>订单状态</h4><p>在 <code>/app/fecshop/common/config/fecshop_local_services\Order.php</code> 中定义</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">    <span class="comment">// 下面是订单支付状态</span></span><br><span class="line">    <span class="comment">// 等待付款状态</span></span><br><span class="line">    <span class="string">'payment_status_pending'</span>            =&gt; <span class="string">'payment_pending'</span>,</span><br><span class="line">    <span class="comment">// 付款处理中，(支付处理中，因为信用卡有预售，因此需要等IPN消息来确认是否支付成功)</span></span><br><span class="line">    <span class="string">'payment_status_processing'</span>         =&gt; <span class="string">'payment_processing'</span>,</span><br><span class="line">    <span class="comment">// 收款成功（支付状态已确认，代表已经收到钱了）</span></span><br><span class="line">    <span class="string">'payment_status_confirmed'</span>          =&gt; <span class="string">'payment_confirmed'</span>,</span><br><span class="line">    <span class="comment">// 欺诈【当paypal的返回金额和网站金额不一致【以及货币类型】的情况，就会判定该状态】</span></span><br><span class="line">    <span class="string">'payment_status_suspected_fraud'</span>    =&gt; <span class="string">'payment_suspected_fraud'</span>,</span><br><span class="line">    <span class="comment">// 订单支付已取消【用户进入paypal点击取消订单返回网站，或者payment_pending订单超过xx时间未支付被脚本取消，或者客服后台取消】</span></span><br><span class="line">   <span class="string">'payment_status_canceled'</span>            =&gt; <span class="string">'payment_canceled'</span>,</span><br><span class="line">    <span class="comment">// 订单审核中（订单收款成功后，进入erp，需要客服审核，才能开始发货流程，或者可能存在某些问题，被客服暂时挂起）</span></span><br><span class="line">    <span class="string">'status_holded'</span>                     =&gt; <span class="string">'holded'</span>,</span><br><span class="line">    <span class="comment">// 订单备货处理中，从成功收款进入erp并客服审核成功后，进入备货流程 到 发货前的状态</span></span><br><span class="line">    <span class="string">'status_processing'</span>                 =&gt; <span class="string">'processing'</span>,</span><br><span class="line">    <span class="comment">// 订单已发货【订单包裹被物流公司收取后】</span></span><br><span class="line">    <span class="string">'status_dispatched'</span>                 =&gt; <span class="string">'dispatched'</span>,</span><br><span class="line">    <span class="comment">// 订单已退款【已收款订单因为某些原因进行退款，譬如：仓库无货，用户收到货后发现破损退款等】</span></span><br><span class="line">    <span class="string">'status_refunded'</span>                   =&gt; <span class="string">'refunded'</span>,</span><br><span class="line">    <span class="comment">// 订单已完成，【用户收到货物xx时间后，未发起纠纷争端，订单状态标记为已完成】</span></span><br><span class="line">    <span class="string">'status_completed'</span>                  =&gt; <span class="string">'completed'</span>,</span><br><span class="line">]</span><br></pre></td></tr></table></figure>
<p>更多参考：<a href="http://www.fecmall.com/doc/fecshop-guide/instructions/cn-2.0/guide-fecmall_order.html" target="_blank" rel="noopener">http://www.fecmall.com/doc/fecshop-guide/instructions/cn-2.0/guide-fecmall_order.html</a></p>
<h4 id="未支付订单释放商品库存定时脚本"><a href="#未支付订单释放商品库存定时脚本" class="headerlink" title="未支付订单释放商品库存定时脚本"></a>未支付订单释放商品库存定时脚本</h4><p>文档参考：<a href="http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecmall-console-pending-cancel.html" target="_blank" rel="noopener">http://www.fecmall.com/doc/fecshop-guide/develop/cn-2.0/guide-fecmall-console-pending-cancel.html</a></p>
<p>待支付订单在设置的时间内未支付，脚本会将订单状态设置为取消状态（cancel），归还库存。（注意：货到收款订单除外，需要在后台手动修改状态。）</p>
<p>脚本处理函数，见 <code>vendor/fancyecommerce/fecshop/services/Order.php</code><br><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 将xx时间内未支付的pending订单取消掉，并释放产品库存。</span></span><br><span class="line"><span class="comment"> * 这个是后台脚本执行的函数。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">protected</span> <span class="function"><span class="keyword">function</span> <span class="title">actionReturnPendingStock</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $logMessage = [];</span><br><span class="line">    <span class="comment">// 设置多少分钟未支付会归还库存</span></span><br><span class="line">    $minute     = <span class="keyword">$this</span>-&gt;minuteBeforeThatReturnPendingStock;</span><br><span class="line">    $begin_time = strtotime(date(<span class="string">'Y-m-d H:i:s'</span>). <span class="string">' -'</span>.$minute.<span class="string">' minutes '</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 不需要释放库存的支付方式。譬如货到付款，在系统中</span></span><br><span class="line">    <span class="comment">// pending订单，如果一段时间未付款，会释放产品库存，但是货到付款类型的订单不会释放，</span></span><br><span class="line">    <span class="comment">// 如果需要释放产品库存，客服在后台取消订单即可释放产品库存。</span></span><br><span class="line">    $noRelasePaymentMethod = Yii::$service-&gt;payment-&gt;noRelasePaymentMethod;</span><br><span class="line">    $where = [</span><br><span class="line">        [<span class="string">'&lt;'</span>, <span class="string">'updated_at'</span>, $begin_time],</span><br><span class="line">        [<span class="string">'order_status'</span> =&gt; <span class="keyword">$this</span>-&gt;payment_status_pending],</span><br><span class="line">        [<span class="string">'if_is_return_stock'</span> =&gt; <span class="number">2</span>],</span><br><span class="line">    ];</span><br><span class="line">    $logMessage[] = <span class="string">'order_updated_at: '</span>.$begin_time;</span><br><span class="line">    <span class="keyword">if</span> (is_array($noRelasePaymentMethod) &amp;&amp; !<span class="keyword">empty</span>($noRelasePaymentMethod)) &#123;</span><br><span class="line">        $where[] = [<span class="string">'not in'</span>, <span class="string">'payment_method'</span>, $noRelasePaymentMethod];</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    $filter = [</span><br><span class="line">        <span class="string">'where'</span>         =&gt; $where,</span><br><span class="line">        <span class="string">'numPerPage'</span>    =&gt; <span class="keyword">$this</span>-&gt;orderCountThatReturnPendingStock,   <span class="comment">// 设置的每次处理多少条待支付订单</span></span><br><span class="line">        <span class="string">'pageNum'</span>       =&gt; <span class="number">1</span>,</span><br><span class="line">        <span class="string">'asArray'</span>       =&gt; <span class="keyword">false</span>,</span><br><span class="line">    ];</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 从订单表 sales_flat_order 中查询超过设置的时间但未支付的订单</span></span><br><span class="line">    $data   = <span class="keyword">$this</span>-&gt;coll($filter);</span><br><span class="line">    $coll   = $data[<span class="string">'coll'</span>];</span><br><span class="line">    $count  = $data[<span class="string">'count'</span>];</span><br><span class="line">    $logMessage[] = <span class="string">'order count: '</span>.$count;</span><br><span class="line">    <span class="keyword">if</span> ($count &gt; <span class="number">0</span>) &#123;</span><br><span class="line">        <span class="keyword">foreach</span> ($coll <span class="keyword">as</span> $one) &#123;</span><br><span class="line">            <span class="comment">/**</span></span><br><span class="line"><span class="comment">             * service严格上是不允许使用事务的，该方法特殊，是命令行执行的操作。</span></span><br><span class="line"><span class="comment">             * 每一个循环是一个事务。</span></span><br><span class="line"><span class="comment">             */</span></span><br><span class="line">            $innerTransaction = Yii::$app-&gt;db-&gt;beginTransaction();</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                $logMessage[] = <span class="string">'cancel order[begin] increment_id: '</span>.$one[<span class="string">'increment_id'</span>];</span><br><span class="line">                $order_id = $one[<span class="string">'order_id'</span>];</span><br><span class="line">                </span><br><span class="line">                $updateComules = $one-&gt;updateAll(</span><br><span class="line">                    [</span><br><span class="line">                        <span class="string">'if_is_return_stock'</span> =&gt; <span class="number">1</span>,   <span class="comment">// 1代表订单归还了库存，2代表订单没有归还库存，此状态作用：用来标示pending订单是否释放产品库存</span></span><br><span class="line">                        <span class="string">'order_status'</span> =&gt; <span class="keyword">$this</span>-&gt;payment_status_canceled,</span><br><span class="line">                    ],</span><br><span class="line">                    [</span><br><span class="line">                        <span class="string">'order_id'</span>  =&gt; $one[<span class="string">'order_id'</span>],</span><br><span class="line">                        <span class="string">'order_status'</span> =&gt; <span class="keyword">$this</span>-&gt;payment_status_pending,</span><br><span class="line">                        <span class="string">'if_is_return_stock'</span> =&gt; <span class="number">2</span></span><br><span class="line">                    ]</span><br><span class="line">                );</span><br><span class="line">                <span class="comment">/**</span></span><br><span class="line"><span class="comment">                 * 取消订单，只能操作一次，因此，我们在更新条件里面加上了order_id， order_status，if_is_return_stock</span></span><br><span class="line"><span class="comment">                 * 因为在上面查询和当前执行的时间之间，订单可能被进行其他操作，</span></span><br><span class="line"><span class="comment">                 * 如果被其他操作，更改了order_status，那么上面的更新行数就是0行。</span></span><br><span class="line"><span class="comment">                 * 那么事务直接回滚。</span></span><br><span class="line"><span class="comment">                 */</span></span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">empty</span>($updateComules)) &#123;</span><br><span class="line">                    $innerTransaction-&gt;rollBack();</span><br><span class="line">                    <span class="keyword">continue</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="comment">// 查询订单详情表 sales_flat_order_item 的数据</span></span><br><span class="line">                    $product_items = Yii::$service-&gt;order-&gt;item-&gt;getByOrderId($order_id, <span class="keyword">true</span>);</span><br><span class="line">                    Yii::$service-&gt;product-&gt;stock-&gt;returnQty($product_items); <span class="comment">// 归还商品库存或者规格库存</span></span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">//$one-&gt;if_is_return_stock = 1;</span></span><br><span class="line">                <span class="comment">// 将订单取消掉。取消后的订单不能再次支付。</span></span><br><span class="line">                <span class="comment">//$one-&gt;order_status = $this-&gt;payment_status_canceled;</span></span><br><span class="line">                <span class="comment">//$one-&gt;save();</span></span><br><span class="line">                $innerTransaction-&gt;commit();</span><br><span class="line">                $logMessage[] = <span class="string">'cancel order[end] increment_id: '</span>.$one[<span class="string">'increment_id'</span>];</span><br><span class="line">            &#125; <span class="keyword">catch</span> (\<span class="keyword">Exception</span> $e) &#123;</span><br><span class="line">                $innerTransaction-&gt;rollBack();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> $logMessage;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="提交订单"><a href="#提交订单" class="headerlink" title="提交订单"></a>提交订单</h4><p>提交订单，减库存。提交订单入口代码见：<code>vendor/fancyecommerce/fecshop/app/appserver/modules/Checkout/controllers/OnepageController.php</code>的<code>actionSubmitorder方法</code></p>
<p>减库存处理方法，见<code>vendor/fancyecommerce/fecshop/services/product/Stock.php</code>的<code>actionDeduct方法</code><br><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@var</span> array $items</span></span><br><span class="line"><span class="comment"> * example:</span></span><br><span class="line"><span class="comment"> * 	[</span></span><br><span class="line"><span class="comment"> *		[</span></span><br><span class="line"><span class="comment"> *			'product_id' =&gt; 'xxxxx',</span></span><br><span class="line"><span class="comment"> *			'qty' =&gt; 2,</span></span><br><span class="line"><span class="comment"> *          'name' =&gt; 'xxxx',</span></span><br><span class="line"><span class="comment"> *			'custom_option_sku' =&gt; 'cos_1',  # 存在该项，则应该到产品的</span></span><br><span class="line"><span class="comment"> *		],</span></span><br><span class="line"><span class="comment"> *		[</span></span><br><span class="line"><span class="comment"> *			'product_id' =&gt; 'yyyyy',</span></span><br><span class="line"><span class="comment"> *          'name' =&gt; 'xxxx',</span></span><br><span class="line"><span class="comment"> *			'qty' =&gt; 1,</span></span><br><span class="line"><span class="comment"> *		],</span></span><br><span class="line"><span class="comment"> *	]</span></span><br><span class="line"><span class="comment"> *  <span class="doctag">@return</span> bool</span></span><br><span class="line"><span class="comment"> *  扣除产品库存。如果扣除成功，则返回true，如果返回失败，则返回false</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> *  **注意**：在调用该函数的时候必须使用事务，在返回false的时候要回滚。</span></span><br><span class="line"><span class="comment"> *  **注意**：在调用该函数的时候必须使用事务，在返回false的时候要回滚。</span></span><br><span class="line"><span class="comment"> *  **注意**：在调用该函数的时候必须使用事务，在返回false的时候要回滚。</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">protected</span> <span class="function"><span class="keyword">function</span> <span class="title">actionDeduct</span><span class="params">($items = [])</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (!$items) &#123;</span><br><span class="line">        <span class="comment">// 如果 $items 为空，则去购物车取数据。</span></span><br><span class="line">        $cartInfo = Yii::$service-&gt;cart-&gt;getCartInfo(<span class="keyword">true</span>);</span><br><span class="line">        $items = <span class="keyword">isset</span>($cartInfo[<span class="string">'products'</span>]) ? $cartInfo[<span class="string">'products'</span>] : [];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 如果items为空，则返回</span></span><br><span class="line">    <span class="keyword">if</span> (!is_array($items) || <span class="keyword">empty</span>($items)) &#123;</span><br><span class="line">        Yii::$service-&gt;helper-&gt;errors-&gt;add(<span class="string">'cart products is empty'</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">    &#125;    </span><br><span class="line">    <span class="comment">// 查看产品的状态，上下架状态，以及产品库存检查是否够用。</span></span><br><span class="line">    <span class="keyword">foreach</span> ($items <span class="keyword">as</span> $k=&gt;$item) &#123;</span><br><span class="line">        $product_id        = $item[<span class="string">'product_id'</span>];</span><br><span class="line">        $sale_qty           = (int)$item[<span class="string">'qty'</span>];</span><br><span class="line">        $custom_option_sku  = $item[<span class="string">'custom_option_sku'</span>];</span><br><span class="line">        $product = Yii::$service-&gt;product-&gt;getByPrimaryKey($product_id);</span><br><span class="line">        <span class="comment">// 购物车中的产品已经被删除，则会查询不到</span></span><br><span class="line">        <span class="keyword">if</span> (!$product[<span class="string">'sku'</span>]) &#123;</span><br><span class="line">            Yii::$service-&gt;helper-&gt;errors-&gt;add(<span class="string">'product: [ &#123;product_id&#125; ] is not exist'</span>, [<span class="string">'product_id'</span> =&gt; $product_id]);</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125; </span><br><span class="line">        $status = <span class="keyword">$this</span>-&gt;productIsInStock($product, $sale_qty, $custom_option_sku);</span><br><span class="line">        <span class="keyword">if</span> (!$status) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; </span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * $this-&gt;checkItemsStock 函数检查产品是否都是上架状态</span></span><br><span class="line"><span class="comment">     * 如果满足上架状态 &amp;&amp; 零库存为1，则直接返回。</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">$this</span>-&gt;zeroInventory) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>; <span class="comment">// 零库存模式 不会更新产品库存。</span></span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 开始扣除库存。</span></span><br><span class="line">    <span class="keyword">foreach</span> ($items <span class="keyword">as</span> $k=&gt;$item) &#123;</span><br><span class="line">        $product_id         = $item[<span class="string">'product_id'</span>];</span><br><span class="line">        $sale_qty           = (int)$item[<span class="string">'qty'</span>];</span><br><span class="line">        $product_name       = Yii::$service-&gt;store-&gt;getStoreAttrVal($item[<span class="string">'product_name'</span>], <span class="string">'name'</span>);</span><br><span class="line">        $custom_option_sku  = $item[<span class="string">'custom_option_sku'</span>];</span><br><span class="line">        <span class="keyword">if</span> ($product_id &amp;&amp; $sale_qty) &#123;</span><br><span class="line">            <span class="comment">// 应对高并发库存超卖的控制，扣除库存的时候，加上qty个数的查询，不满足查询条件则不扣除库存</span></span><br><span class="line">            $updateColumns = <span class="keyword">$this</span>-&gt;_flatQtyModel-&gt;updateAllCounters(</span><br><span class="line">                [<span class="string">'qty'</span> =&gt; <span class="number">0</span> - $sale_qty],</span><br><span class="line">                [<span class="string">'and'</span>, [<span class="string">'product_id'</span> =&gt; $product_id], [<span class="string">'&gt;='</span>, <span class="string">'qty'</span>, $sale_qty]]</span><br><span class="line">            );</span><br><span class="line">            <span class="keyword">if</span> (<span class="keyword">empty</span>($updateColumns)) &#123;<span class="comment">// 上面更新sql返回的更新行数如果为0，则说明更新失败，产品不存在，或者产品库存不够</span></span><br><span class="line">                Yii::$service-&gt;helper-&gt;errors-&gt;add(<span class="string">'product: [ &#123;product_name&#125; ] is stock out'</span>, [<span class="string">'product_name'</span> =&gt; $product_name]);</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// 对于custom option（淘宝模式）的库存扣除</span></span><br><span class="line">            <span class="keyword">if</span> ($custom_option_sku) &#123;</span><br><span class="line">                $updateColumns = <span class="keyword">$this</span>-&gt;_COQtyModel-&gt;updateAllCounters(</span><br><span class="line">                    [<span class="string">'qty'</span> =&gt; <span class="number">0</span> - $sale_qty],</span><br><span class="line">                    [</span><br><span class="line">                        <span class="string">'and'</span>,</span><br><span class="line">                        [</span><br><span class="line">                            <span class="string">'custom_option_sku'</span> =&gt; $custom_option_sku,</span><br><span class="line">                            <span class="string">'product_id'</span>        =&gt; $product_id</span><br><span class="line">                        ],</span><br><span class="line">                        [<span class="string">'&gt;='</span>,<span class="string">'qty'</span>,$sale_qty]</span><br><span class="line">                    ]</span><br><span class="line">                );</span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">empty</span>($updateColumns)) &#123;<span class="comment">// 上面更新sql返回的更新行数如果为0，则说明更新失败，产品不存在，或者产品库存不够</span></span><br><span class="line">                    Yii::$service-&gt;helper-&gt;errors-&gt;add(<span class="string">'product: [ &#123;product_name&#125; ] is stock out'</span>, [<span class="string">'product_name'</span> =&gt; $product_name]);</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h3 id="支付"><a href="#支付" class="headerlink" title="支付"></a>支付</h3><h4 id="订单支付成功后处理"><a href="#订单支付成功后处理" class="headerlink" title="订单支付成功后处理"></a>订单支付成功后处理</h4><p>见：<code>vendor/fancyecommerce/fecshop/services/payment/Alipay.php</code></p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> $increment_id | String 订单号</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> $sendEmail | boolean 是否发送邮件</span></span><br><span class="line"><span class="comment">   * 订单支付成功后，需要更改订单支付状态等一系列的处理。</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="keyword">protected</span> <span class="function"><span class="keyword">function</span> <span class="title">paymentSuccess</span><span class="params">($increment_id, $trade_no, $sendEmail = true)</span></span></span><br><span class="line"><span class="function">  </span>&#123;</span><br><span class="line">      Yii::$service-&gt;store-&gt;currentLangCode = <span class="string">'zh'</span>;</span><br><span class="line">      <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;_order) &#123;</span><br><span class="line">          <span class="keyword">$this</span>-&gt;_order = Yii::$service-&gt;order-&gt;getByIncrementId($increment_id);</span><br><span class="line">          Yii::$service-&gt;payment-&gt;setPaymentMethod(<span class="keyword">$this</span>-&gt;_order[<span class="string">'payment_method'</span>]);</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="comment">// 【优化后的代码 ##】</span></span><br><span class="line">      $orderstatus = Yii::$service-&gt;order-&gt;payment_status_confirmed;</span><br><span class="line">      $updateArr[<span class="string">'order_status'</span>]  = $orderstatus;</span><br><span class="line">      $updateArr[<span class="string">'txn_id'</span>]        = $trade_no; <span class="comment">// 支付宝的交易号</span></span><br><span class="line">      $updateColumn = <span class="keyword">$this</span>-&gt;_order-&gt;updateAll(</span><br><span class="line">          $updateArr,</span><br><span class="line">          [</span><br><span class="line">              <span class="string">'and'</span>,</span><br><span class="line">              [<span class="string">'order_id'</span> =&gt; <span class="keyword">$this</span>-&gt;_order[<span class="string">'order_id'</span>]],</span><br><span class="line">              [<span class="string">'in'</span>,<span class="string">'order_status'</span>,<span class="keyword">$this</span>-&gt;_allowChangOrderStatus]</span><br><span class="line">              <span class="comment">//  $this-&gt;_allowChangOrderStatus :</span></span><br><span class="line">              <span class="comment">//  Yii::$service-&gt;order-&gt;payment_status_pending  / Yii::$service-&gt;order-&gt;payment_status_processing,</span></span><br><span class="line">          ]</span><br><span class="line">      );</span><br><span class="line">      <span class="keyword">if</span> (!<span class="keyword">empty</span>($updateColumn)) &#123;</span><br><span class="line">          <span class="comment">// 发送邮件，以及其他的一些操作（订单支付成功后的操作）</span></span><br><span class="line">          Yii::$service-&gt;order-&gt;orderPaymentCompleteEvent(<span class="keyword">$this</span>-&gt;_order[<span class="string">'increment_id'</span>]);</span><br><span class="line">      &#125;</span><br><span class="line">     </span><br><span class="line">      <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    

    
    
    
<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">------本文结束<i class="fa fa-paw"></i>感谢阅读------</div>
    
</div>
  
</div>
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>欣赏此文？求鼓励，求支持！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechat.png" alt="云舒 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="云舒 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>云舒</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://blog.yunshu168.com/posts/f5f4aa82.html" title="fecshop开源商城学习笔记">http://blog.yunshu168.com/posts/f5f4aa82.html</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/商城/" rel="tag"># 商城</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/posts/753d374a.html" rel="next" title="亿级Web系统搭建：单机到分布式集群[转]">
                <i class="fa fa-chevron-left"></i> 亿级Web系统搭建：单机到分布式集群[转]
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/posts/6e943b7a.html" rel="prev" title="FA 用户数据分析系统学习笔记">
                FA 用户数据分析系统学习笔记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        
  <div class="bdsharebuttonbox">
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
    <a href="#" class="bds_douban" data-cmd="douban" title="分享到豆瓣网"></a>
    <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
    <a href="#" class="bds_tieba" data-cmd="tieba" title="分享到百度贴吧"></a>
    <a href="#" class="bds_twi" data-cmd="twi" title="分享到Twitter"></a>
    <a href="#" class="bds_fbook" data-cmd="fbook" title="分享到Facebook"></a>
    <a href="#" class="bds_more" data-cmd="more"></a>
    <a class="bds_count" data-cmd="count"></a>
  </div>
  <script>
    window._bd_share_config = {
      "common": {
        "bdText": "",
        "bdMini": "2",
        "bdMiniList": false,
        "bdPic": ""
      },
      "share": {
        "bdSize": "16",
        "bdStyle": "0"
      },
      "image": {
        "viewList": ["tsina", "douban", "sqq", "qzone", "weixin", "twi", "fbook"],
        "viewText": "分享到：",
        "viewSize": "16"
      }
    }
  </script>

<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

      
    </div>
  </div>


          </div>
          

  
    <div class="comments" id="comments">
      
        <div id="gitment-container"></div>
      
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="云舒" />
            
              <p class="site-author-name" itemprop="name">云舒</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives">
                
                    <span class="site-state-item-count">68</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">5</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">28</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/yunshu2009" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:yunshu.luo@gmail.com" target="_blank" title="E-Mail"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://www.cnblogs.com/luoyunshu/" target="_blank" title="Cnblogs"><i class="fa fa-fw fa-globe"></i>Cnblogs</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://www.bilibili.com" target="_blank" title="bilibili"><i class="fa fa-fw fa-globe"></i>bilibili</a>
                  
                </span>
              
            </div>
          

          
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#订单"><span class="nav-number">1.</span> <span class="nav-text">订单</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#数据表结构"><span class="nav-number">1.1.</span> <span class="nav-text">数据表结构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#订单状态"><span class="nav-number">1.2.</span> <span class="nav-text">订单状态</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#未支付订单释放商品库存定时脚本"><span class="nav-number">1.3.</span> <span class="nav-text">未支付订单释放商品库存定时脚本</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#提交订单"><span class="nav-number">1.4.</span> <span class="nav-text">提交订单</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#支付"><span class="nav-number">2.</span> <span class="nav-text">支付</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#订单支付成功后处理"><span class="nav-number">2.1.</span> <span class="nav-text">订单支付成功后处理</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2012 &mdash; <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">云舒</span>

  

  
</div>




  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/theme-next/hexo-theme-next">NexT.Pisces</a></div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.0.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.0.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.0.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.0.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.0.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.0.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.0.4"></script>



  



	





  





  






<!-- LOCAL: You can save these files to your site and update links -->
    
        
         <!-- <link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css"> -->
        <!-- <script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script> -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/theme-next/theme-next-gitment@1/default.css">
        <script src="https://cdn.jsdelivr.net/gh/theme-next/theme-next-gitment@1/gitment.browser.js"></script>
    
<!-- END LOCAL -->

    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitment({
            id: decodeURI(window.location.pathname),
            owner: 'yunshu2009',
            repo: 'yunshu2009.github.io',
            
            oauth: {
            
            
                client_secret: '15cdd9dc30fb9e0c97260bf79fe09d158fa04b22',
            
                client_id: '9495da16cda475a5e221'
            }});
        gitment.render('gitment-container');
      }

      
      renderGitment();
      
      </script>
    






  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  
  

  

  

  

  


</body>
</html>
